import os
import shutil


def organize_files(base_dir):
    # 定义子目录路径
    patterns_dir = os.path.join(base_dir, "MMSI_Patterns")
    trajectories_dir = os.path.join(base_dir, "Detailed_Trajectories")

    # 创建子目录，如果它们不存在
    os.makedirs(patterns_dir, exist_ok=True)
    os.makedirs(trajectories_dir, exist_ok=True)

    # 遍历基目录中的所有文件
    for filename in os.listdir(base_dir):
        # 忽略子目录
        if os.path.isdir(os.path.join(base_dir, filename)):
            continue

        # 根据文件名决定移动文件到哪个子目录
        if filename.startswith("cluster_") and filename.endswith("_mmsis.csv"):
            # 属于模式文件
            shutil.move(os.path.join(base_dir, filename), os.path.join(patterns_dir, filename))
        elif filename.endswith("_detailed.csv"):
            # 属于具体数据文件
            shutil.move(os.path.join(base_dir, filename), os.path.join(trajectories_dir, filename))


if __name__ == "__main__":
    base_dir = "./Data/Groups/CSJ/New_Human_Trajectories/MMSI_Cluster_Groups"
    organize_files(base_dir)
    print("Files have been organized into subdirectories.")
